package com.springcloud.hystrix.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.springcloud.entities.CommonResult;
import com.springcloud.entities.Payment;
import com.springcloud.hystrix.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Title: PaymentController
 * Description: TODO
 *
 * @author gejx
 * @version V1.0
 * @date 2021-12-29
 */
@RestController
@Slf4j

public class PaymentController {
    @Resource
    private PaymentService paymentService;

    @Value("${server.port}")
    private String paymentPort;

    @GetMapping("/payment/get/ok/{id}")

    public String paymentInfo_ok(@PathVariable("id") Integer id){
//        int a=10/0;
        String s = paymentService.paymentInfo_ok(id);
        log.info(s);
        return s;
    }

    @GetMapping("/payment/get/timeout/{id}")
    public String paymentInfo_Timeout(@PathVariable("id")Integer id){
        String s = paymentService.paymentInfo_Timeout(id);
        log.info(s);
        return s;
    }
    //服务熔断

    @GetMapping("/payment/circuit/{id}")
    public String paymentCircuitBreaker(@PathVariable("id") Integer id)
    {
        String result = paymentService.paymentCircuitBreaker(id);
        log.info("****result: "+result);
        return result;
    }
}
